<?php
require_once("./DButil.php");

// // 默认值
// $pageNum = 1;
// if(isset($_REQUEST["pageNum"])) {
//     // 有此参数时, 使用给定的值
//     $pageNum = $_REQUEST["pageNum"];
// }
// $pageSize = 2;

// // 查询可供分页使用的总数据量
// $sql = "select count(1) count from t_product where p_status = 1";
// $products = query($sql);
// // 总数据量
// $count = $products[0]["count"];
// // 总页数
// $totalPage = ceil($count/$pageSize);

// $m = ($pageNum - 1) * $pageSize;
// $n = $pageSize;





$id = $_REQUEST["id"];
$name = $_REQUEST["name"];
$begin = $_REQUEST["begin"];
$end = $_REQUEST["end"];

$sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id={$id}";
$arr = query($sql);
$p = $arr[0];
header("Content-Type:application/json;charset=utf-8");
echo json_encode($p);



$sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_name like '%{$name}%' limit {$m},{$n}";
// $arr = query($sql);
// $p = $arr;
// header("Content-Type:application/json;charset=utf-8");
// echo json_encode($p);

$sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_price between {$begin} and {$end} limit {$m},{$n}";
// $arr = query($sql);
// $p = $arr;
// header("Content-Type:application/json;charset=utf-8");
// echo json_encode($p);


// if($id&&$name&&$begin&&$end){
//     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id={$pid} and p_name like '%{$name}%' and p_price between {$begin} and {$end} ";
// }else if($id&&$name&&$end){
//     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id={$pid} and p_name like '%{$name}%' and p_price <= {$end} ";
// }else if($id&&$name&&$begin){
//     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id={$pid} and p_name like '%{$name}%' and p_price >= {$begin} ";
// }else if($id&&$name&&$begin){
//     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id={$pid} and p_name like '%{$name}%' and p_price >= {$begin} ";
// }else if($begin&&$end){
//     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id={$pid} and p_price between {$begin} and {$end} ";
// }else if($id&&$name){
//     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id={$pid} and p_name like '%{$name}%'  ";
// }else if($id){
//     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_id={$pid}  ";
// }else if($name){
//     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_name like '%{$name}%'  ";
// }else if($begin){
//     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_price >= {$begin}  ";
// }else if($end){
//     $sql = "select p_id,p_name,p_price,p_unit,p_image_url from t_product where p_price <= {$end}  ";
// }


// $arr = query($sql);
// $p = $arr;
// header("Content-Type:application/json;charset=utf-8");
// echo json_encode($p);
?>